var url = window.location.href; // 获取完整的URL  
var searchParams = new URLSearchParams(window.location.search); // 获取URL中的参数部分  
uid = searchParams.get("uid");
// 获取初始数据
$.ajax({
    url: '/noinfo/update_theme_get/',
    type: 'GET',
    async: false,
    dataType: 'json',
    data: {
        'id': uid,
    },
    success: function(data) {
        product = JSON.parse(data.theme)[0].fields;
        $.each(product, function(key, value) {
            if (key == 'theme' || key == 'status_type' || key == 'status_view') {
                $('#' + key).text(value);
            } else {
                $('#' + key).val(value); 
            } 
        });
        if(product.status_type == '动画'){
            $('#status_type').css('color', '#1E90FF');
        }else if(product.status_type == '电影'){
            $('#status_type').css('color', '#808080');
        }else if(product.status_type == '电视剧'){
            $('#status_type').css('color', '#84C9EF');
        }else if(product.status_type == '小说'){
            $('#status_type').css('color', '#00AC6B');
        }
    }
});

// 修改
$('input').each(function() {  
    if ($(this).prop('disabled')) {  
        $(this).css({
            'border': 'none',
            'background-color': 'transparent',
        });  
    }  
  });

// 提交数据
$('#submit').click(function() {
    var theme = $("#theme").val();
    var status_view = $("#status_view").val();
    var source_name = $("#source_name").val();
    var source_type = $("#source_type").val();
    var universe = $("#universe").val();
    var author = $("#author").val();
    // 发送AJAX请求
    $.ajax({
        url: '/noinfo/update_theme_post/',
        type: 'POST',
        dataType: 'json',
        data: { 
            id: uid,
            theme: theme,
            status_view: status_view,
            source_name: source_name,
            source_type: source_type,
            universe: universe,
            author: author,
        },
        success: function(data) {
            if(data.code == 'success') {
                alert(theme + ' 修改完成');
                location.reload();
                
            } else {
                alert(data.code);
            }  
        },
        error: function(xhr, status, error) {
            alert('ajax执行失败');
          }
        });
})
